package com.iemp.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class IPUtils {

    public static String ipv4() throws IOException {
        Process exec = Runtime.getRuntime().exec("curl https://ipv4.icanhazip.com/");
        InputStream in = exec.getInputStream();

        byte[] buffer = new byte[1024];
        int len = 0;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        while ((len = in.read(buffer)) != -1) {
            bos.write(buffer, 0, len);
        }
        bos.close();
        byte[] bytes = bos.toByteArray();
        return (new String(bytes, "UTF-8")).replace("\n", "").replace(" ","");
    }

}
